<template>
  <!-- 修改素材授权 -->
  <div class="change-auth" :style="{'zIndex': showDialog ? '200' : '2'}">
    <div class="cell-wrapper">
      <div class="cell" @click="toggleDialog">
        <div class="label">授权方式</div>
        <div class="right">
          <span class="green-text">{{ type }}</span>
          <img src="@/assets/image/right-icon.png" alt="" class="right-icon"/>
        </div>
      </div>
      <div 
        class="material-list"
        v-if="type === '部分授权'"
      >
        <div class="item" v-for="(item, index) in list" :key="index">
          <p><span>{{ item.name + (index + 1)}}—</span><span class="gray-text">产品</span></p>
          <p>
            <span class="red-text">移出</span>
            <img src="@/assets/image/auth-del.png" alt="" class="del-icon">
          </p>
        </div>
       
        <div class="item">
          <p><span>—</span><span class="gray-text">产品</span></p>
          <p @click="remove(index)">
            <span class="red-text">移出</span>
            <img src="@/assets/image/auth-del.png" alt="" class="del-icon">
          </p>
        </div>
        <div class="add-material" @click="chooseMaterialPack">+选择授权素材包</div>
      </div>
    </div>

    <van-popup v-model="showDialog"  position="bottom">
      <div class="popup-content">
        <div 
          class="line" @click="lineClick('全部授权')"
          :class="type == '全部授权' ? 'active': ''"
          >
          <span>全部授权</span>
          <img src="@/assets/image/popup-check.png" alt=""/>
        </div>
        <div 
          :class="type == '部分授权' ? 'active': ''"
          class="line" @click="lineClick('部分授权')">
          <span>部分授权</span>
          <img src="@/assets/image/popup-check.png" alt=""/>
        </div>
        <div 
          :class="type == '不授权' ? 'active': ''"
          class="line" @click="lineClick('不授权')">
          <span>不授权</span>
          <img src="@/assets/image/popup-check.png" alt=""/>
        </div>
      </div>
    </van-popup>
  </div>
</template>

<script>
export default {
  props: {
    choosedList: {
      type: Array,
      default: function () {
        return []
      }
    }
  },
  data () {
    return {
      type: '全部授权',
      showDialog: false,
      list: []
    }
  },
  mounted () {
    if (this.choosedList.length) {
      this.type = '部分授权'
      this.list = this.choosedList
    }
  },
  methods: {
    chooseMaterialPack () {
      this.$emit('addMaterial')
    },
    remove (index) {
      console.log('remove index:', index)
    },
    lineClick (type) {
      this.type = type
      this.showDialog = false
      this.$emit('change', type)
    },
    toggleDialog () {
      this.showDialog = true
    }
  }
}
</script>

<style scoped>
.add-material {
  text-align: right;
  font-family: Source Sans Pro;
  font-size: 3.73vw;
  font-weight: 600;
  line-height: 5.87vw;
  color: #006EDD;
}
.red-text {
  margin-right: 0.8vw;
  font-family: Source Sans Pro;
  font-size: 3.2vw;
  font-weight: 600;
  color: #D81E06;
}
.del-icon {
  width: 4vw;
  height: 4vw;
}
.gray-text {
  color: #999999;
}
.material-list {
  box-sizing: border-box;
  padding-top: 4.27vw;
  border-top: 0.32vw solid #E6E6E6;
  padding-bottom: 5.33vw;
}
.item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-sizing: border-box;
  height: 5.87vw;
  margin-bottom: 3.2vw;
  padding-left: 2.13vw;
  font-family: Source Sans Pro;
  font-size: 3.73vw;
  font-weight: 600;
  color: #666;
}
.item:last-of-type {
  margin-bottom: 5.33vw;
}
.item > p {
  display: flex;
  align-items: center;
}
.green-text {
  margin-right: 2.13vw;
  font-family: Source Sans Pro;
  font-size: 3.2vw;
  font-weight: 600;
  color: #00A6A7;
}
.line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 16vw;
  line-height: 16vw;
  box-sizing: border-box;
  padding-left: 8vw;
  padding-right: 9.33vw;
  font-family: Source Sans Pro;
  font-size: 4.8vw;
  font-weight: bold;
  line-height: 7.47vw;
  color: #333333;
}
.line > img {
  display: none;
  width: 3.47vw;
  height: 2.13vw;
}
.line.active {
  background: #E6F2FF;
  color: #0A67FF;
}
.line.active > img {
  display: block;
}
::v-deep .van-overlay {
  background: rgba(0,0,0,0.3);
}
::v-deep .van-popup {
  border-radius: 10px 10px 0 0;
}
.popup-content {
  box-sizing: border-box;
  padding-top: 5.33vw;
  height: 65.87vw;
  width: 100vw;
  background: #fff;
  border-radius: 10px 10px 0 0;
}
.right {
  display: flex;
  align-items: center;
}
.right-icon {
  width: 3vw;
  height: 3vw;
}
.cell-wrapper {
  width: 89.6vw;
  margin: 0 auto;
  box-shadow: 0px 2px 8px 0px rgba(0, 0, 0, 0.12);
  background: #fff;
  border-radius: 2.13vw;
  padding: 0 5.33vw 0 3.2vw;
  box-sizing: border-box;
}
.cell {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 89.6vw;
  height: 16.53vw;
  padding: 0 5.33vw 0 3.2vw;
  box-sizing: border-box;
}
.change-auth {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  min-height: 100vh;
  box-sizing: border-box;
  padding-top: 5.33vw;
  background: #fff;
  z-index: 2;
}
.label {
  font-family: Source Sans Pro;
  font-size: 3.73vw;
  font-weight: bold;
  line-height: 5.87vw;
  color: #333333;
}
</style>